<%-- 
    Document   : header.jsp
    Created on : Apr 3, 2012, 12:52:27 AM
    Author     : Mr. Hung
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" media="all" />
        <link href="style.css" rel="stylesheet" type="text/css" />

    </head>
    <body>
        <div id="headbar-wrap">
            <div id="head-bar">
                <h1>
                    <a href="ViewHome">Befriends</a>
                    <a href="ViewHome"><span>Connecting friends</span></a>
                </h1>

                <%
                    ServletContext context = request.getServletContext();
                    String currentPath = request.getRequestURL().toString();
                    int firstSplit = 0;
                    int lastSplit = 0;
                    for (int i = currentPath.length() - 1; i >= 0; i--) {
                        if (currentPath.charAt(i) == '/') {
                            firstSplit = i + 1;
                            break;
                        }
                    }
                    String pageName = currentPath.substring(firstSplit);
                %>

                <ul class="main-menu" style="overflow:visible">
                    <%
                        if (pageName.equals("home.jsp")) {
                            out.println("<li><a class=\"current\" href=\"ViewHome\">Home</a><li>");
                        } else {
                            out.println("<li><a href=\"ViewHome\">Home</a><li>");
                        }

                        if (pageName.equals("personal.jsp")) {
                            out.println("<li><a class=\"current\" href=\"ViewPersonalInfo\" onclick=\"\">Personal</a></li>");
                        } else {
                            out.println("<li><a href=\"ViewPersonalInfo\" onclick=\"\">Personal</a></li>");
                        }

                        if (pageName.equals("settings.jsp")) {
                            out.println("<li><a class=\"current\" href=\"Settings\">Settings</a></li>");
                        } else {
                            out.println("<li><a href=\"Settings\">Settings</a></li>");
                        }

                        if (pageName.equals("search_match.jsp")) {
                            out.println("<li><a class=\"current\" href=\"Matching\">Suggest</a></li>");
                        } else {
                            out.println("<li><a href=\"Matching\">Suggest</a></li>");
                        }

                        out.println("<li><a href=\"Logout\">Logout</a></li>");
                    %>
                </ul>

                <ul class="main-2-menu">
                    <li id="acc_name">
                        <a href="ViewPersonalInfo" id="user">
                            <img src="${sessionScope.account.avatar}" height="36" width="36">
                            <span>${sessionScope.account.username}</span>
                        </a>
                    </li>
                    <li>  
                        <form action="SearchByUsername" method="get">
                            <input id="search_box" type="text" name="usernameToFind" placeholder="Search"  onKeyPress="return press_enter(this,event)"> 
                        </form>
                    </li>
                </ul>
            </div><!--end div#head-bar -->
            <script type="text/javascript">
                <!--
                function press_enter(field,event)
                {
                    var keycode;
                    if (window.event) keycode = window.event.keyCode;
                    else if (event) keycode = event.which;
                    else return true;

                    if (keycode == 13)
                    {
                        field.form.submit();
                        return false;
                    }
                    else
                        return true;
                }
                //-->
            </script>
            <%-- Java script to validate search by username --%>
            <script type="text/javascript">
                function validateSearch(form) {
                    if (form.usernameToFind.value != "") {
                        form.submit();
                    }
                }
            </script>
        </div><!--end header-->
        <div id="header_bg">
        </div>
    </body>
</html>

